package experiment.experiment5;

/**
 * Created by lenovo on 2016/5/8.
 */
import java.net.*;
import java.io.*;
import java.util.Scanner;

public class Client1{
    public static void main(String srgs[]) throws Exception {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入明文：");
        String m = scanner.nextLine();
        String cs;
        cs = Enc_RSA.main(m);
        try {
            //创建连接特定服务器的指定端口的Socket对象
            Socket socket = new Socket("222.28.131.142",14512);
            //获得从服务器端来的网络输入流
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            //获得从客户端向服务器端输出数据的网络输出流
            PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
            //创建键盘输入流，以便客户端从键盘上输入信息
            //BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

            out.println(cs);  //通过网络传送到服务器
            cs = in.readLine();//从网络输入流读取结果
            System.out.println( "从服务器接收到的结果为："+ cs); //输出服务器返回的结果
        }
        catch (Exception e) {
            System.out.println(e);
        }
        finally{
            //stdin.close();
            //in.close();
            //out.close();
            //socket.close();
        }
    }
}
